package org.fujay.langchain4jserver.infrastructure.persistence.assembler;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.fujay.langchain4jserver.domain.application.vo.AppId;
import org.fujay.langchain4jserver.domain.conversation.entity.Conversation;
import org.fujay.langchain4jserver.domain.conversation.vo.ConversationId;
import org.fujay.langchain4jserver.domain.conversation.vo.UserId;
import org.fujay.langchain4jserver.infrastructure.persistence.mybatis.entity.ConversationPo;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ConversationAssembler {

    public static Conversation toDomainEntity(final ConversationPo po) {
        if (po == null) {
            return null;
        }
        return Conversation.load(
                new ConversationId(po.getId()),
                new UserId(po.getUserId()),
                new AppId(po.getAppId()),
                po.getTitle(),
                po.getCreateTime(),
                po.getUpdateTime());
    }

    public static ConversationPo toPO(final Conversation entity) {
        ConversationPo po = new ConversationPo();
        po.setId(entity.getId().value());
        po.setUserId(entity.getUserId().value());
        po.setAppId(entity.getAppId().value());
        po.setTitle(entity.getTitle());
        return po;
    }


}
